var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("Item"),
    i = t("Util"),
    s = cc._decorator,
    c = s.ccclass,
    l = s.property,
    u = s.menu,
    p = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (e.item = null), e;
        }
        var o;
        return (
            n(e, t),
            (o = e),
            Object.defineProperty(e.prototype, "datas", {
                get: function () {
                    return this._datas;
                },
                set: function (t) {
                    this._datas = t;
                    for (var e = 0, n = this.content.children; e < n.length; e++) {
                        var r = this._datas[e],
                            i = n[e],
                            s = i.getComponent(a.default);
                        if (r) (s.data = r), (s.index = e), s.refresh();
                        else {
                            var c = i.children[0];
                            this.returnNode(c), (i.parent = null), o.pool.put(i), e--;
                        }
                    }
                    for (; e < this._datas.length; e++) {
                        r = this._datas[e];
                        null == (s = o.pool.get()) && (s = new cc.Node()).addComponent(a.default),
                            (s.name = "" + e),
                            (s.x = 0),
                            (s.y = 0),
                            (s.width = this.item.width),
                            (s.height = this.item.height),
                            s.getComponent(a.default).setdata(this, e, r),
                            this.content.addChild(s);
                    }
                },
                enumerable: !1,
                configurable: !0
            }),
            (e.prototype.getNode = function () {
                var t = this.handle.pool.get();
                return null == t && (((t = cc.instantiate(this.item)).x = 0), (t.y = 0), (t.active = !0)), t;
            }),
            (e.prototype.returnNode = function (t) {
                var e = this;
                null != t &&
                    ((t.parent = null),
                    i.scheduleOnce(function () {
                        e.handle.pool.put(t);
                    }));
            }),
            (e.prototype.setNode = function (t, e) {
                this.handle.fun.call(this.handle.the, e, t.data, t.index);
            }),
            (e.prototype.onEnable = function () {
                if (
                    ((this.scrollView = this.getComponent(cc.ScrollView)),
                    (this.content = this.scrollView.content),
                    null == this.content)
                )
                    throw Error("没有设置 sorcllView 的 content");
                this.scrollView.vertical && (this.content.anchorY = 1);
            }),
            (e.prototype.returnPool = function () {
                this.scrollView.stopAutoScroll();
                for (var t = this.content.children.slice(), e = 0; e < t.length; e++) {
                    var n = t[e],
                        r = n.children[0];
                    this.returnNode(r), (n.parent = null), o.pool.put(n);
                }
            }),
            (e.prototype.onDisable = function () {
                this.returnPool();
            }),
            (e.pool = new cc.NodePool()),
            r([l(cc.Node)], e.prototype, "item", void 0),
            (e = o = r([c, u("列表/List")], e))
        );
    })(cc.Component);
o.default = p;
